﻿@using KRM.Core
@model IEnumerable<tblPromotion>
@{
    tblUser user = ViewBag.User;
}
<link href="~/css/jquery.treeview.css" rel="stylesheet" />
<script src="~/js/jquery.treeview.min.js"></script>
<div id="modalProductOption">
    <div id="promotionOption" class="modal hide fade" style="width: 700px;" tabindex="-1" role="dialog" aria-labelledby="addController" aria-hidden="true">
        <div class="container-fluid">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h5>Product Option Selection</h5>
            </div>
            <div class="modal-body">
                <div class="row-fluid">
                    <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs margin0">
                        <li class="active">
                            <a href="#searchOp" data-toggle="tab">Search</a>
                        </li>
                        <li>
                            <a href="#treesearch" data-toggle="tab" onclick="loadTreeSearch();">Tree</a>
                        </li>
                    </ul>

                    <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content" style="height: 330px; overflow: auto;">
                        <div class="tab-pane active" id="searchOp">
                            <div class="container-fluid">
                                <div class="row-fluid">
                                    Product Id or Product name
                                    <div class="span12" style="margin-left: 0px;">
                                        <form method="POST" action="products/SearchProductOption" id="frm-searchproduct">
                                            <div class="span10">
                                                <input type="text" id="nameproduct" name="nameproduct" class="input-block-level" />
                                            </div>
                                            <div class="span2">
                                                <input type="submit" class="btn btn-primary w90" value="Search" />
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                <div class="row-fluid">
                                    <div id="tableProductSearch" style="height: 200px;">
                                        
                                    </div>
                                </div>
                                <div class="row-fluid">
                                    Product Option
                                    <div class="span12" style="">
                                        <select id="selectProductOption" class="span12">
                                            <option value="0">--Choose an option--</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="treesearch"></div>
                        <input type="hidden" id="hdProductOption" value=""/>
                    </div>
                </div>
            </div>

            <div class="modal-footer">
                <div class="row-fluid">
                    <div class="span12">
                        <button class="btn w90" data-dismiss="modal" aria-hidden="true">Close</button>
                        <button class="btn btn-primary w90" onclick="addPromotionProductOption();">Add</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="modalWebsite">
    <script>
        $(document).ready(function () {
            $("#tree").treeview({
                animated: "fast",
                collapsed: true,
            });
            $("#treeview a").click(function () {
                $("#treeview a").removeClass("tree-selected");
                $(this).addClass("tree-selected");
                var value = $(this).attr("val");
                $('#lblRelatedCat').html(value + " - " + this.innerHTML);
                $('#hdRelCat').val(value);
            });
        });

    </script>
    <style>
        .treeview p {margin-bottom: 0px !important;}
        .display {color: rgb(198, 198, 198);}
        .tree-selected {color: red;}
    </style>

    <div id="promotionWebsite" class="modal hide fade" data-width="700" tabindex="-1" role="dialog" aria-labelledby="addController" aria-hidden="true">
        <div class="container-fluid">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h5>Promotion Website</h5>
            </div>
            <div class="modal-body">
                <input type="hidden" id="promositeid" value="@ViewBag.Id"/>
                <div class="row-fluid">
                    <div class="span3">Position</div>
                    <div class="span4">
                        <input type="text" id="positionPromo" class="input-block-level" value="@ViewBag.Position" />
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3">Website</div>
                    <div class="span9">
                        @Html.DropDownList("StoreID", null, new { @class = "input-block-level", onchange = "changeCatTree(this.value)" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span3"></div>
                    <div class="span9">
                        <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs margin0">
                            <li class="active">
                                <a href="#treeview" data-toggle="tab">Tree view</a>
                            </li>
                            <li>
                                <a href="#listview" data-toggle="tab">List view</a>
                            </li>
                            @*<li>
                            <a href="#promotions" data-toggle="tab">Promotions</a>
                        </li>*@
                        </ul>

                        <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content" style="height: 268px; overflow: auto;">
                            <div class="tab-pane active" id="treeview">
                                @Html.Raw(ViewBag.Tree)
                            </div>
                            <div class="tab-pane" id="listview">
                                <div class="row-fluid">
                                    @Html.Raw(ViewBag.List)
                                </div>
                            </div>
                            @*<div class="tab-pane" id="promotions">
                            
                        </div>*@
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal-footer">
                <div class="row-fluid">
                    <div class="span6">
                        <div class="span3">Related Category:</div>
                        <div class="span9">
                            <div class="span2"><a onclick=" $('#treeview a').removeClass('tree-selected');$('#lblRelatedCat').empty();$('#hdRelCat').val('');">Clear</a></div>
                            <div class="span10">
                                <label id="lblRelatedCat">@ViewBag.Cate</label>
                                <input type="hidden" id="hdRelCat" value="@ViewBag.CateId"/>
                            </div>
                        </div>
                    </div>
                    <div class="span6">
                        <button class="btn btn-primary w90" data-dismiss="modal" aria-hidden="true" onclick="savePromoWebsite()">OK</button>
                        <button class="btn w90" data-dismiss="modal" aria-hidden="true">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row-fluid">
    <div class="span4">
        <div class="border-padding10">
            <div class="row-fluid">
                <div class="span12">
                    <a href="/products/newpromotion" class="btn btn-success input-block-level"
                        @(user.HasPermission(Permissions.PromotionCanCreate) ? "" : "disabled=disabled") >New Promotion</a>
                </div>
            </div>
            <div style="margin: 10px 0">
                <label>
                    <input class="cbcheck" type="checkbox" id="ckShow" onchange="showarchivedchange($(this))" />
                    Show Archived Promotions</label>
            </div>
            <div class="promotionlist">
                <table class="table table-bordered table-fix krmtable tbl-selected" data-height="735">
                    <thead>
                        <tr>
                            <th></th>
                            <th>ID</th>
                            <th>Promotion</th>
                            <th>EndDate</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            var value = 1;
                            if (!item.Active) { value = -1; }
                            else if (item.EndDate < DateTime.Now) { value = 0; }
                            <tr onclick="promotionselected(@item.ID)" @(!item.Active ? "class=rownotarchived" : "")>
                                <td>@value</td>
                                <td>@item.ID</td>
                                <td>@item.Name</td>
                                <td>@item.EndDate</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>

        </div>
    </div>
    <div class="span8">
        <div class="border-padding10 promotiondetail"></div>
    </div>
</div>
